package rpg.core
{

	/**
	 * 自动销毁的组件
	 * @author hyy
	 *
	 */
	public class AutoDestroyComponent extends FrameComponent
	{
		protected var duration : int;
		protected var palyElapsedTime : int;

		public function AutoDestroyComponent(type : *)
		{
			super(type);
		}

		override public function update(delay : uint) : void
		{
			palyElapsedTime += delay;
			if(palyElapsedTime >= duration)
			{
				timeOut();
			}
		}

		public function timeOut() : void
		{
			destroy();
		}

		/**
		 *
		 * @param duration
		 *
		 */
		public function setDration(value : int) : void
		{
			if(value <= duration)
				return;
			if(value <= 0)
				destroy();
			palyElapsedTime = 0;
			this.duration = value;
		}
	}
}